package com.dailyblue.example.project.bookstore.order.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.example.project.bookstore.commons.bean.Order;
import com.dailyblue.example.project.bookstore.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "order_group", topic = "ORDER1", selectorExpression = "ORDER",messageModel = MessageModel.BROADCASTING)
public class OrderListener implements RocketMQListener<String> {
    @Resource
    private OrderService service;

    @Override
    public void onMessage(String s) {
        Order order = JSONArray.parseObject(s, Order.class);
        log.info("order:{}",order);
        service.save(order);
    }
}
